package com.javaee.term.controller;
import com.javaee.term.Enums.PrintStatusEnum;
import com.javaee.term.data.AnalyOver;
import com.javaee.term.data.ConverAnaly;
import com.javaee.term.data.TurnOver;
import com.javaee.term.model.Customer;
import com.javaee.term.service.ContactService;
import com.javaee.term.service.CustomerService;
import com.javaee.term.service.ProductService;
import com.javaee.term.service.SalemanService;
import com.javaee.term.service.iml.ContactServiceIml;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * author 陈伯瑞
 * date 2019/12/22 0022 17:39
 * version 1.0
 **/
@Controller
@RequestMapping("/seller/dataHand")
@Slf4j
public class DataHandController {
    @Autowired
    ContactService contactService;
    @Autowired
    ProductService productService;
    @Autowired
    CustomerService customerService;
    @Autowired
    SalemanService salemanService;
    static Calendar now = Calendar.getInstance();

    @GetMapping("/analy")
    public ModelAndView analy(Map<String, Object> map) {
        return new ModelAndView("dataAnaly/data", map);
    }
    @GetMapping("/analyMonth")
    public ModelAndView analy1(Map<String, Object> map) {
        return new ModelAndView("dataAnaly/dataMonth", map);
    }

    @GetMapping("/analyWeek")
    public ModelAndView analy2(Map<String, Object> map) {
        return new ModelAndView("dataAnaly/dataWeek", map);
    }

    @GetMapping("/analyProduct")
    public ModelAndView analy3(Map<String, Object> map) {
        return new ModelAndView("dataAnaly/dataProduct", map);
    }
    @GetMapping("/analyCustomer")
    public ModelAndView analy4(Map<String, Object> map) {
        return new ModelAndView("dataAnaly/dataCustomer", map);
    }
    @GetMapping("/analySaleMan")
    public ModelAndView analy5(Map<String, Object> map) {
        return new ModelAndView("dataAnaly/dataSaleMan", map);
    }

    @GetMapping("/analy/turnOver")
    @ResponseBody
    public List<TurnOver> getsum(){
        return contactService.getTrunOverData();
    }

    @GetMapping("/analy/turnOverMonth")
    @ResponseBody
    public List<TurnOver> getsum1() {
        return contactService.getTheSumEachMouth( String.valueOf(now.get(Calendar.YEAR))).stream()
                .peek(e->e.setLabel(e.getLabel()+"月")).collect(Collectors.toList());
    }
    @GetMapping("/analy/turnOverWeek")
    @ResponseBody
    public List<TurnOver> getsum2() {
        return contactService.getTheSumEachWeek(String.valueOf(now.get(Calendar.YEAR)));
    }

    @GetMapping("/analy/productTurnOver")
    @ResponseBody
    public List<TurnOver> getProductSum() {
     return  productService.getAllProductTurnOver();
    }

    @GetMapping("/analy/customerTurnOver")
    @ResponseBody
    public List<TurnOver>   getCustomerSum() {
        return customerService.getAllCustomerTurnOver();
    }
    @GetMapping("/analy/saleManTurnOver")

    @ResponseBody
    public List<TurnOver>   getSaleManSum() {
        return  salemanService.getAllSalesmanTurnOver();
    }

    @GetMapping("/analy/saleManTurnOverMonth")
    @ResponseBody
    public List<TurnOver>   getSaleManSum1(HttpSession session) {
        Object manIdMap = session.getAttribute("manId");
        Integer manId=(Integer)manIdMap;
        return  salemanService.getTheSumEachMouth(String.valueOf(now.get(Calendar.YEAR)),manId).stream()
                .peek(e->e.setLabel(e.getLabel()+"月")).collect(Collectors.toList());
    }
    @GetMapping("/analy/saleManTurnOverYear")
    @ResponseBody
    public List<TurnOver>   getSaleManSum2(HttpSession session) {
        Object manIdMap = session.getAttribute("manId");
        Integer manId=(Integer)manIdMap;
        return  salemanService.getTheSumEachYear(manId);
    }
}

